package com.smartwebx.ha.dal.util;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;

import com.google.common.base.Objects;

/**
 * 水情时间处理
 * 
 * @author zhangxi
 * 
 */
public class WaterDatePoints {

	/**
	 * 获得经过处理的开始结束日期
	 * 
	 * @param start
	 * @param end
	 * @return
	 */
	public static Date[] getStartEndPoint(Date start, Date end) {
		Date now = new Date();
		int nowHour = (int) DateUtils.getFragmentInHours(now, Calendar.DATE);
		now = DateUtils.truncate(now, Calendar.DATE);
		Date newEnd = DateUtils.truncate(end, Calendar.DATE);

		if (Objects.equal(newEnd, now)) {
			end = DateUtils.addHours(end, nowHour);
		} else {
			end = DateUtils.addDays(newEnd, 1);
		}

		return new Date[] { start, end };
	}

}
